<html>
<head>
     <meta charset='UTF-8'>
     <title>socket.io客户端</title>
     <script src='http://localhost:3036/socket.io/socket.io.js'></script>
</head>
<body>
     <button id='send'>发送消息到服务器</button>
     <div>
          <h3>服务器响应的消息：</h3>
          <i id='msg'></i>
     </div>

     <script>
          var socket = io.connect('ws://localhost:3036/');
          var send = document.querySelector('#send');
          var msg = document.querySelector('#msg');

          socket.on('update', data => {
              console.log('服务端消息：',  JSON.parse(data));
              msg.innerHTML = `${data} <br/>`;
          })
          socket.on('init', data => {
               console.log('ganma');
              console.log('服务端消息：',  JSON.parse(data));
          })
          socket.emit('join',JSON.stringify({
               name: '陈皮阿四',
               view: {width:800,height:600}
          }))
          console.log(socket);
          send.onclick = () => {
               console.log('点击了发送消息！');
               socket.emit('update1', 'hello');
          }
     </script>
</body>
</html>